class RegisterCodesController < ApplicationController
  layout "blank_scaffold"
  before_filter :admin_required

  active_scaffold :register_code do |config|
    config.list.per_page = 10
    config.columns = [:id, :code, :limit, :total, :expire_date]
    config.create.columns.exclude :id, :code, :total
    config.update.columns.exclude :id, :code
    config.list.sorting = {:id => 'ASC'}
  end

  def before_create_save(record)
    chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
    newpass = ""
    1.upto(10) { |i| newpass << chars[rand(chars.size-1)] }
    record.code = newpass
    record.total = 0
  end
end
